<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>操作日志</title>
    	<script language="JavaScript" src="${pageContext.request.contextPath}/luhong/mydate.js"></script>
    	<script type="text/javascript">
    		//清空时间
    		function freeTime(){
    			document.getElementById("starttime").value="";
    			document.getElementById("endtime").value="";
    		}
    		//创建并返回异步请求对象
			function createXMLHttpRequest(){
				var xmlReq=new XMLHttpRequest();
				return xmlReq;
			}
			var xmlHttpReq;
			//添加部门数据(第一步)
			function initDeptData(){
				var url="${pageContext.request.contextPath}/sendEmail.action?method=QueryDeptAjax";
				//1.创建异步请求对象
				xmlHttpReq=createXMLHttpRequest();
				//2.建立到服务器的新请求
				xmlHttpReq.open("get",url,true);
				//3.设定服务器的回调方法 
				xmlHttpReq.onreadystatechange=addDeptData;
				//4.发送异步请求
				xmlHttpReq.send(null);
			}
			//添加部门数据(第二步,第一步的回调函数)
			function addDeptData(){
				if(xmlHttpReq.readyState==4){
					if(xmlHttpReq.status==200){
						var xmldoc=xmlHttpReq.responseXML;
						deptSelect(xmldoc);
					}
				}
			}
			//添加部门数据(第三步,得到queryDeptAjax里的值,添加到页面上)
			function deptSelect(xmldoc){
				var selobj=document.getElementById("dept");
				var idArray=xmldoc.getElementsByTagName("id");
				var nameArray=xmldoc.getElementsByTagName("name");
				for(var i=0;i<idArray.length;i++){
					var optObj=document.createElement("option");
					optObj.value=idArray[i].innerHTML;
					optObj.text=nameArray[i].innerHTML;
					selobj.appendChild(optObj);
				}
			}
			//查询日志
			function queryLogData(){
    			//先判断一下时间
    			var stime=document.getElementById("starttime").value;
    			var etime=document.getElementById("endtime").value;
    			if(starttime!=""&&endtime!=""){
    				if(starttime>endtime){
    					alert("时间上限晚于时间下限！");
    					return;
    				}
    			}
    			var deptid=document.getElementById("dept").value;
    			var url="${pageContext.request.contextPath}/OperationManager.action?method=query&starttime="+stime+"&endtime="+etime+"&dept="+deptid;
    			window.location.href=url;
    		}
    		function skipPage(currentPage){
        		var url='${pageContext.request.contextPath }/OperationManager.action?method=query&currPage='+currentPage;
        		window.location.href=url;
      		}
      		var oldColor;
			function choice(trObj) {
				oldColor = trObj.bgColor;
				trObj.bgColor = "yellow";
			}
			function leave(trObj) {
				trObj.bgColor = oldColor;
			}
    	</script>
    	<style type="text/css">
    		a{
    			cursor:pointer;
    		}
    		body {
				background-image:
				url(${pageContext.request.contextPath}/images/forum7.jpg);
			}
    	</style>
    </head>
  
  <body onload="initDeptData();">
  	<form method="post">
   	时间:<input type="text" name="starttime" id="starttime" onfocus="MyCalendar.SetDate(this)" value="${requestScope.starttime }" readonly>
   		--<input type="text" name="endtime" id="endtime" onfocus="MyCalendar.SetDate(this)" value="${requestScope.endtime }" readonly>
   	<input type="button" value="清空时间" onclick="freeTime();">
   	部门：
   	<select id="dept" name="dept">
		<option value="-1">
			所有部门
		</option>
	</select>
   	<input type="button" value="查询" onclick="queryLogData();" id="queryId">
   	</form>
   	<br/>
   	<br/>
   	<div style="height:320px;">
   	 <table align="center" border="1px" cellspacing="0px" cellpadding="0px">
   	 	<tr>
   	 		<td>操作人</td>
   	 		<td>操作内容</td>
   	 		<td>部门名称</td>
   	 		<td>操作时间</td>
   	 	</tr>
   	 	<c:forEach items="${requestScope.logPage.logdata}" var="view" varStatus="c">
   	 		<tr bgcolor="${c.index%2==0?'white':'skyblue'}" onmouseover=choice(this); onmouseout=leave(this);>
   	 			<td>${view.operaterId }</td>
   	 			<td>${view.logContent }</td>
   	 			<td>${view.deptId }</td>
   	 			<td>${view.logTime }</td>
   	 		</tr>
   	 	</c:forEach>
   	 </table>
   	 </div>
	<table align="center">
			<tr>
				<td>
					<a onclick=
	skipPage('1');;
>首页</a>
				</td>
				<td>
					<a
						onclick="skipPage('${requestScope.logPage.currentPage==1?1:requestScope.logPage.currentPage-1 }');">上一页</a>
				</td>
				<td>
					<a
						onclick="skipPage('${requestScope.logPage.currentPage==requestScope.logPage.totalPage?(requestScope.logPage.currentPage):(requestScope.logPage.currentPage+1) }');">下一页</a>
				</td>
				<td>
					<a onclick="skipPage('${requestScope.logPage.totalPage}');">末页</a>
				</td>
				<td>
					当前页码：${requestScope.logPage.currentPage
					}/${requestScope.logPage.totalPage}
				</td>
			</tr>
		</table>   	 
  </body>
</html>
